﻿// JScript File
Global.namespace("System.Web.Handler");
System.Web.Handler.RequestHandler=function(){}

// get person info
System.Web.Handler.RequestHandler.getPerson=function(personId, callback)
{
    var params = {};
    params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.PROFILE_URL];
    
    var req = opensocial.newDataRequest();
    req.add(req.newFetchPersonRequest(personId, params), "person");
    req.send(callback);
}

System.Web.Handler.RequestHandler.getOwner=function(callback){
    var request = opensocial.newDataRequest();
    var fields = [  
                    opensocial.Person.Field.ID,
				    opensocial.Person.Field.AGE,
				    opensocial.Person.Field.BODY_TYPE,
				    opensocial.Person.Field.BOOKS,
				    opensocial.Person.Field.CHILDREN,
				    opensocial.Person.Field.CURRENT_LOCATION,
				    opensocial.Person.Field.DATE_OF_BIRTH,
				    opensocial.Person.Field.NAME,
				    opensocial.Person.Field.NICKNAME,
				    opensocial.Person.Field.PROFILE_SONG,
				    opensocial.Person.Field.PROFILE_URL,
				    opensocial.Person.Field.RELATIONSHIP_STATUS,
				    opensocial.Person.Field.RELIGION,
				    opensocial.Person.Field.SEXUAL_ORIENTATION,
				    opensocial.Person.Field.SMOKER,
				    opensocial.Person.Field.STATUS,
				    opensocial.Person.Field.THUMBNAIL_URL,
				    opensocial.Person.Field.TV_SHOWS,
				    opensocial.Person.Field.GENDER,
				    opensocial.Person.Field.URLS
				];

    var params = {};
    params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = fields;
    params[opensocial.DataRequest.DataRequestFields.ESCAPE_TYPE] = opensocial.EscapeType.HTML_ESCAPE;

    var ctr=this;
    var idspec = opensocial.newIdSpec({ "userId" : "OWNER", "groupId" : "FRIENDS" });
    var req = opensocial.newDataRequest();
    
    
    req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER, params), "owner");
    
    req.send(function(response){
        var owner = response.get('owner').getData(); 
        callback(owner);
    });
}
// get list of friends
System.Web.Handler.RequestHandler.getFriends=function(callback){
        var request = opensocial.newDataRequest();
        // create a list of Person fields to fetch,
        // in this case, include all supported fields.
        var fields = [  
                        opensocial.Person.Field.ID,
					    opensocial.Person.Field.AGE,
					    opensocial.Person.Field.BODY_TYPE,
					    opensocial.Person.Field.BOOKS,
					    opensocial.Person.Field.CHILDREN,
					    opensocial.Person.Field.CURRENT_LOCATION,
					    opensocial.Person.Field.DATE_OF_BIRTH,
					    opensocial.Person.Field.NAME,
					    opensocial.Person.Field.NICKNAME,
					    opensocial.Person.Field.PROFILE_SONG,
					    opensocial.Person.Field.PROFILE_URL,
					    opensocial.Person.Field.RELATIONSHIP_STATUS,
					    opensocial.Person.Field.RELIGION,
					    opensocial.Person.Field.SEXUAL_ORIENTATION,
					    opensocial.Person.Field.SMOKER,
					    opensocial.Person.Field.STATUS,
					    opensocial.Person.Field.THUMBNAIL_URL,
					    opensocial.Person.Field.TV_SHOWS,
					    opensocial.Person.Field.GENDER,
					    opensocial.Person.Field.URLS
					];

	    var params = {};
	    params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = fields;
        params[opensocial.DataRequest.DataRequestFields.ESCAPE_TYPE] = opensocial.EscapeType.HTML_ESCAPE;

        var ctr=this;
	    var idspec = opensocial.newIdSpec({ "userId" : "OWNER", "groupId" : "FRIENDS" });
	    var req = opensocial.newDataRequest();
	    
	    req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER, params), "get_owner");
	    req.add(req.newFetchPeopleRequest(idspec, params), "friends");
        req.send(callback);
}